<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
    $customer = $this->getCustomer();
    
    $billingAddress = $customer->getDefaultBillingAddress();
    
    
    $shippingAddress = $customer->getDefaultShippingAddress();

    //var_dump($billingAdress);
    //die;
    //$billingAdress = Mage::getModel("customer/customer")->load()
?>
<div class="wrapper-main">
    <div class="headlabel"><?php echo $this->__('SIGN IN') ?></div><br />
    <p class="notes"><?php echo $this->__('* Indicate required field') ?> <div class="account"><a href="<?php echo $this->getUrl('sales/order/history') ?>" class="build"><?php echo $this->__('Order History') ?></a></div></p><br />
    
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <form class="jNice" action="<?php echo $this->getUrl('customer/account/editPost') ?>" method="post" id="form-validate">
        <div class="content-create">
            <div class="col-1">
            <?php echo $this->getBlockHtml('formkey')?>
                <div class="box-left register">
                    <div class="box-left register">
                        <h4 class="legend"><?php echo $this->__('Your Information') ?></h4>
                        <div class="content-box">
                            <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
                            <fieldset>
                                <label for="company" class="required"><?php echo $this->__('Company Name') ?><span>*</span></label>
                                <input type="text" name="company" class="required-entry" id="company" value="<?php echo $customer->getCompany() ?>" title="<?php echo $this->__('Company Name') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('companyname') ?>" />
                            </fieldset>
                        </div>
                        
                        <!--
                        <label for="email" class="required"><em>*</em><?php //echo $this->__('Email Address') ?></label>
                        <div class="input-box">
                            <input type="text" name="email" id="email" value="<?php //echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php //echo $this->__('Email Address') ?>" class="input-text required-entry validate-email" />
                        </div>
                        -->

                        <?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>

                        <?php if ($_dob->isEnabled()): ?>
                            <?php echo $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?>
                        <?php endif ?>
                        <?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
                        <?php if ($_taxvat->isEnabled()): ?>
                            <?php echo $_taxvat->setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?>
                        <?php endif ?>
                        <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
                        <?php if ($_gender->isEnabled()): ?>
                            <?php echo $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?>
                        <?php endif ?>

                    </div>
                </div>
                <div style="clear:left"></div>
                <div style="margin:10px;">
                    <input type="checkbox" name="change_password" id="change_password" value="1" onclick="setPasswordForm(this.checked)" title="<?php echo $this->__('Change Password') ?>"<?php if($this->getCustomer()->getChangePassword()==1): ?> checked="checked"<?php endif; ?> class="checkbox" /><label for="change_password"><?php echo $this->__('Change Password') ?></label>
                </div>
                <div class="box-left register">

                    <h4 class="legend"><?php echo $this->__('Change Password') ?></h4>
                        <div class="content-box">
                            <fieldset>
                                <label><?php echo $this->__("Email") ?><span></span></label>
                                <!--<input type="text" name="email" id="email" value="<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text required-entry validate-email" />-->
                                <?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>
                            </fieldset>
                            <fieldset>
                                <label for="current_password" class="required"><?php echo $this->__('Current Password') ?>
                                    <span>*</span>
                                </label>
                                <input type="password" title="<?php echo $this->__('Current Password') ?>" class="" name="current_password" id="current_password" />
                            </fieldset>

                            <fieldset>
                                <label for="password" class="required"><?php echo $this->__('New Password') ?><span>*</span></label>
                                <input type="password" title="<?php echo $this->__('New Password') ?>" class="validate-password" name="password" id="password" />
                            </fieldset>
                            <fieldset>
                                <label for="confirmation" class="required"><?php echo $this->__('Confirm Password') ?><span>*</span></label>
                                <input type="password" title="<?php echo $this->__('Confirm Password') ?>" class="validate-cpassword" name="confirmation" id="confirmation" />
                            </fieldset>
                     </div>
                </div>
                <div class="box-left register">
                    <h4><?php echo $this->__("Contact Information") ?></h4>
                    <div class="content-box">
                        <fieldset>
                            <label for="telephone" class="required"><?php echo $this->__('Phone') ?><span>*</span></label>
                            <?php if(!empty($billingAddress)): ?>
                                <input type="text" name="telephone" id="telephone" value="<?php echo $billingAddress->getTelephone(); ?>" title="<?php echo $this->__('Telephone') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" />
                            <?php else: ?>
                                <input type="text" name="telephone" id="telephone" value="" title="<?php echo $this->__('Telephone') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" />
                            <?php endif; ?>
                        </fieldset>
                        
                        <fieldset>
                            <label><?php echo $this->__("Fax") ?><span></span></label>
                            <input type="text" class="" name="fax" id="fax" value="<?php echo $customer->getFax() ?>" />
                        </fieldset>
                        <fieldset>
                            <label><?php echo $this->__("Website") ?><span></span></label>
                            <input type="text" class="" name="account_website" id="account_website" value="<?php echo $customer->getAccountWebsite() ?>" />
                        </fieldset>
                    </div>
                </div><!--end box left-->

                <?php //getDefaultBillingAddress() ?>
                <div class="box-left register">
                        <h4><?php  echo $this->__("Company Information") ?></h4>
                        <div class="content-box">
                            <fieldset>
                                <p class="bold">Please tell us a little about your business and how<br /> you like to use our parts?</p><br />
                                <p>*(In 500 words or less)</p>
                            </fieldset>

                            <fieldset>
                                <textarea id="company_info" maxlength="500" name="company_info" class="required-entry"><?php echo $customer->getCompanyInfo()?></textarea>
                            </fieldset>
                        </div>
                </div>
                
            </div>
            <div class="col-2">
                <div class="box-left register">
                    <h4><?php echo $this->__("Billing Address") ?></h4>
                    <div class="content-box">
                        <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
                        <?php $street=array(0=>"",1=>""); ?>
                        <?php if(!empty($billingAddress)): ?>
                            <?php $street = $billingAddress->getStreet() ?>

                        <?php endif ?>
                        
                        <fieldset>
                            <label><?php echo $this->__("Address") ?><span>*</span></label>
                            <input type="text" name="street[]" value="<?php echo @$street[0] ?>" id="street_1" class="<?php echo $_streetValidationClass ?>" />
                        </fieldset>
                        <fieldset>
                            <label>Address(line2)</label>
                            <input type="text" name="street[]" value="<?php echo @$street[1] ?>" id="street_2" class="<?php //echo $_streetValidationClass ?>" />
                        </fieldset>
                        <fieldset>
                            <label><?php echo $this->__("City") ?><span>*</span></label>
                            <?php if(!empty($billingAddress)): ?>
                            <input type="text" name="city" value="<?php echo $billingAddress->getCity() ?>" title="<?php echo $this->__('City') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
                            <?php else:?>
                            <input type="text" name="city" value="" title="<?php echo $this->__('City') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
                            <?php endif;?>
                        </fieldset>
                        <fieldset>
                            <label for="region_id" class="required"><?php echo $this->__('State') ?><span>*</span></label>
                                <select id="region_id" name="region_id" title="<?php echo $this->__('State') ?>" class="validate-select" style="display:none;">
                                    <option value=""><?php echo $this->__('Please select region, state') ?></option>
                                </select>
                                <script type="text/javascript">
                                //<![CDATA[
                                    $('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
                                //]]>
                                </script>
                                <?php if(!empty($billingAddress)): ?>
                                    <input type="text" id="region" class="required-entry" name="region" value="<?php echo $billingAddress->getRegion() ?>" title="<?php echo $this->__('State') ?>"  style="display:none;" />
                                <?php else: ?>
                                    <input type="text" id="region" class="required-entry" name="region" value="" title="<?php echo $this->__('State') ?>"  style="display:none;" />
                                <?php endif ?>
                        </fieldset>
                        
                        <fieldset>
                            <label for="country" class="required"><?php echo $this->__('Country') ?><span>*</span></label>
                            <?php $_countries = Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false) ?>
                            
                            <?php if (count($_countries) > 0): ?>
                                <select name="country_id" id="country" class="required-entry">
                                    <?php foreach($_countries as $_country): ?>
                                        <?php if(!empty($billingAddress)): ?>
                                        <?php $country_id = $billingAddress->getCountryId() ?>
                                        <?php else: ?>
                                        <?php $country_id=""; ?>
                                        <?php endif; ?>
                                        <?php if($country_id==$_country['value']): ?>
                                            <option selected value="<?php echo $_country['value'] ?>">
                                                <?php echo $_country['label'] ?>
                                            </option>
                                        <?php else:?>
                                            <option value="<?php echo $_country['value'] ?>">
                                                <?php echo $_country['label'] ?>
                                            </option>
                                        <?php endif;?>
                                        
                                    <?php endforeach; ?>
                                </select>
                            <?php endif; ?>
                        </fieldset>
                        <fieldset>
                            <label for="zip" class="required"><?php echo $this->__('Zip Code') ?><span>*</span></label>
                            <input type="text" name="postcode" value="<?php echo  $billingAddress->getPostcode() ?>" title="<?php echo $this->__('Zip Code') ?>" id="zip" class="zipcode validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
                            <input type="hidden" name="address_id" value="<?php echo $billingAddress->getAddressId() ?>" />
                            <input type="hidden" name="id" value="<?php echo $billingAddress->getId() ?>" />
                        </fieldset>
                        
                    </div>
                </div>
        
                <div class="box-left register">
                    <h4><?php echo $this->__("Shipping Address") ?></h4>
                    <div class="content-box">
                        <!--<fieldset> <input type="checkbox" name="default_billing" value="1" /><span class="text-check">Same as billing</span></fieldset>-->
                        <!--<fieldset> <input type="checkbox" value="1" /><span class="text-check">Is this a Residence?</span></fieldset>-->

                        <fieldset>
                                <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
                                <?php $street = $shippingAddress->getStreet() ?>
                                <label for="street_1" class="required"><?php echo $this->__('Address') ?><span>*</span></label>
                                <input type="text" name="shipping_street[]" value="<?php echo @$street[0] ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="<?php echo $_streetValidationClass ?>" />
                        </fieldset>
                        <fieldset>
                                <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
                                
                                <label for="street_1" class=""><?php echo $this->__('Address 2') ?></label>
                                <input type="text" name="shipping_street[]" value="<?php echo @$street[1] ?>" title="<?php echo $this->__('Street Address') ?>" id="street_2" class="<?php //echo $_streetValidationClass ?>" />
                        </fieldset>
                        

                        <fieldset>
                                <label for="city" class="required"><?php echo $this->__('City') ?><span>*</span></label>
                                <input type="text" name="shipping_city" value="<?php echo $shippingAddress->getCity() ?>" title="<?php echo $this->__('City') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="shipping_city" />
                        </fieldset>
                        <fieldset>
                                <label for="region_id" class="required"><?php echo $this->__('State/Province') ?><span>*</span></label>
                                <select id="shipping_region_id" class="required-entry" name="shipping_region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
                                    <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                                </select>
                                <script type="text/javascript">
                                //<![CDATA[
                                    $('shipping_region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
                                //]]>
                                </script>
                                <input type="text" id="shipping_region" name="shipping_region" class="required-entry" value="<?php echo $shippingAddress->getRegion() ?>" title="<?php echo $this->__('State/Province') ?>" style="display:none;" />
                        </fieldset>
                        <fieldset>
                            <label for="shipping_country" class="required"><?php echo $this->__('Country') ?><span>*</span></label>
                            <?php $_countries = Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false) ?>
                            <?php if (count($_countries) > 0): ?>
                                <select name="shipping_country" class="required-entry" id="shipping_country">

                                    <?php foreach($_countries as $_country): ?>
                                        <?php $country_id = $shippingAddress->getCountryId() ?>
                                        <?php if($country_id==$_country['value']): ?>
                                            <option selected value="<?php echo $_country['value'] ?>">
                                                <?php echo $_country['label'] ?>
                                            </option>
                                        <?php else:?>
                                            <option value="<?php echo $_country['value'] ?>">
                                                <?php echo $_country['label'] ?>
                                            </option>
                                        <?php endif;?>
                                    <?php endforeach; ?>
                                </select>
                            <?php endif; ?>
                        </fieldset>
                        <fieldset>
                                <label for="shipping_poscode" class="required"><?php echo $this->__('Zip/Postal Code') ?><span>*</span></label>
                                <input type="text" name="shipping_postcode" value="<?php echo $shippingAddress->getPostcode(); ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="zipcode validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
                                <input type="hidden" name="shipping_address_id" value="<?php echo $shippingAddress->getId() ?>" />
                                <input type="hidden" name="shipping_id" value="<?php echo $shippingAddress->getId() ?>" />
                        </fieldset>
                    </div>
                </div><!--end box left-->
                <!--
                <div class="box-left register">
                    <h4><?php //echo $this->__("Preferred Shipping Method") ?></h4>
                    <div class="content-box">
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS Ground ($14.46)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS 3 Day Selectsm ($16.46)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS 2 Dat Air® ($121.84)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS 2nd Day Air A.M.® ($23.84)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS Next Day Air® ($33.12)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS Next Day Air Saver® ($29.40))</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check">UPS Next Day Air® Early A.M.® ($68.61)</span></fieldset>
                        <fieldset><input name="aa" type="radio" /><span class="text-check left">UPS Collect Account Shipping</span><input type="text" value="1234567" class="acship" /></fieldset>
                        <p style=" color:#003366">Your invoice may ravy from the displayed reference rates</p>
                    </div>
                </div>
                -->
            </div>
            <div class="bottom clear">
                <fieldset class="acept">
                    <?php $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail()) ?>
                    <?php $status = $subscriber->getSubscriberStatus() ?>
                    
                    <input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($status==1): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    <span class="bold">  <?php echo $this->__("Yes, I would like to receive newsletter!") ?></span>
                </fieldset>
                <fieldset>
                    <button type="submit" title="<?php echo $this->__('Submit') ?>" class="submit"><span><span><?php echo $this->__('Submit') ?></span></span></button>
                    <button type="reset" class="cancel" value="Cancel" onclick="window.location='<?php echo $this->getUrl(); ?>'; return false;" ><span><span><?php echo $this->__('Cancel') ?></span></span></button>
                </fieldset>
            </div>
        </div>
       
    </form>
</div>
<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('form-validate', true);

    function setPasswordForm(arg){
        if(arg){

            $('current_password').up(3).show();
            $('current_password').addClassName('required-entry');
            $('password').addClassName('required-entry');
            $('confirmation').addClassName('required-entry');

        }else{
            $('current_password').up(3).hide();
            $('current_password').removeClassName('required-entry');
            $('password').removeClassName('required-entry');
            $('confirmation').removeClassName('required-entry');
        }
    }
    <?php if($this->getCustomer()->getChangePassword()): ?>
        setPasswordForm(true);
    <?php endif; ?>
   
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
        new RegionUpdater('shipping_country', 'shipping_region', 'shipping_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
   
//]]>
</script>
